<template>
  <div>
    <template>
      <Card style="width:850px;margin: auto;">
        <Form :model="formLeft" label-position="left" :label-width="100" style="width: 300px;margin: auto;">


          <FormItem label="路线代码">
            <Select v-model="formLeft.routingCode">
              <Option v-for="item in routingList" :value="item.code">{{ item.code }}</Option>
            </Select>
          </FormItem>

          <FormItem label="工艺流程代码">
            <Select v-model="formLeft.processCode">
              <Option v-for="item in processList" :value="item.code">{{ item.code }}</Option>
            </Select>
          </FormItem>

          <FormItem label="上一站工艺流程代码">
            <Select v-model="formLeft.previousProcessCode">
              <Option v-for="item in processList" :value="item.code">{{ item.code }}</Option>
            </Select>
          </FormItem>

          <FormItem label="下一站工艺流程代码">
            <Select v-model="formLeft.nextProcessCode">
              <Option v-for="item in processList" :value="item.code">{{ item.code }}</Option>
            </Select>
          </FormItem>

          <row type="flex" justify="center">
            <i-col span="20">
            </i-col>
            </i-col>
            <i-col span="30">
              <Button type="primary" @click="RoutingProcessUpdateById">修改</Button>
              <Button type="success" style="margin-left: 160px" @click="back">返回</Button>
            </i-col>
          </row>

        </Form>
      </Card>
    </template>
  </div>
</template>

<script>
  import {RoutingProcessFindById, RoutingProcessUpdateById, RoutingFindAll, ProcessFindAll} from "../../../api/data"

  export default {
    data() {
      return {
        page: 1,//page 第几页
        pageSize: 1000,//pageSize:每页几条数据
        routingList: [],
        processList: [],
        formLeft: {
          routingCode: '',
          processCode: '',
          previousProcessCode: '',
          nextProcessCode: ''
        },
        validateLibForm: {
          routingCode: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          processCode: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          previousProcessCode: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          nextProcessCode: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
        }
      }
    },
    mounted() {
      const idFlag = this.$route.query.id;
      if (idFlag) {
        this.formLeft.id = idFlag;
        this.RoutingFindAll();
        this.ProcessFindAll();
        this.RoutingProcessFindById();
      }
    },
    methods: {
      RoutingFindAll() {
        var data = {
          page: this.page,
          pageSize: this.pageSize,
        };
        RoutingFindAll(data).then(data => {
          if (data.data.code == 0) {
            this.routingList = data.data.data.list;
          }
        })
      },
      ProcessFindAll() {
        var data = {
          page: this.page,
          pageSize: this.pageSize,
        };
        ProcessFindAll(data).then(data => {
          if (data.data.code == 0) {
            this.processList = data.data.data.list;
          }
        })
      },
      RoutingProcessUpdateById() {
        if (this.formLeft.routingCode !== null && this.formLeft.routingCode !== "") {
          if (this.formLeft.processCode !== null && this.formLeft.processCode !== "") {
            if (this.formLeft.previousProcessCode !== null && this.formLeft.previousProcessCode !== "") {
              if (this.formLeft.nextProcessCode !== null && this.formLeft.nextProcessCode !== "") {
                RoutingProcessUpdateById(this.formLeft).then(res => {
                  this.$Message.success("编辑成功");
                  this.$router.go(-1)
                })
              } else {
                this.$Message.error("下一站工艺流程代码不能为空");
              }
            } else {
              this.$Message.error("上一站工艺流程代码不能为空");
            }
          } else {
            this.$Message.error("工艺流程代码不能为空");
          }
        } else {
          this.$Message.error("路线代码不能为空");
        }
      },
      back() {
        this.$router.go(-1);
      },
      RoutingProcessFindById() {
        var data = {
          id: this.formLeft.id,
        }
        RoutingProcessFindById(data).then(res => {
          this.formLeft = res.data.data;
        })
      }
    },

  }
</script>


